#include "testApp.h"

//--------------------------------------------------------------
void testApp::setup(){
    ofSetFrameRate(60);
    
    rectCoord.set(ofGetWidth()/2, ofGetHeight()/2);
    ofBackground(250, 0, 100);
    
    mouseCoord.set(0, 0);
    
    dir.set(7, 23);
    dir.normalize();
    
    velocity = 0;
    
    accel = .01;
    
    force.set(0, .1);
    
    momentum.set(0,0);
}

//--------------------------------------------------------------
void testApp::update(){
    
    dir = mouseCoord - rectCoord;
    dir.normalize();
    
    if(ofGetKeyPressed(32)){
        //velocity += accel;
        velocity = 5;
        
        momentum = dir * velocity;
    } else {
        //velocity -= accel * 3;
        velocity = 0;
        
        momentum += force;
    }
    
    if(velocity < 0){
        velocity = 0;
    }

    
    rectCoord += momentum;
    
    if(rectCoord.y >= ofGetHeight() - 10){
        rectCoord.y = ofGetHeight() - 10;
        momentum.y *= -0.2;
    }
}

//--------------------------------------------------------------
void testApp::draw(){
    ofRect(rectCoord, 10, 10);
}

//--------------------------------------------------------------
void testApp::keyPressed(int key){
}

//--------------------------------------------------------------
void testApp::keyReleased(int key){

}

//--------------------------------------------------------------
void testApp::mouseMoved(int x, int y ){
    mouseCoord.set(x, y);
}

//--------------------------------------------------------------
void testApp::mouseDragged(int x, int y, int button){

}

//--------------------------------------------------------------
void testApp::mousePressed(int x, int y, int button){

}

//--------------------------------------------------------------
void testApp::mouseReleased(int x, int y, int button){

}

//--------------------------------------------------------------
void testApp::windowResized(int w, int h){

}

//--------------------------------------------------------------
void testApp::gotMessage(ofMessage msg){

}

//--------------------------------------------------------------
void testApp::dragEvent(ofDragInfo dragInfo){ 

}